package com.tddx.activiti.common.propertyeditor;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.util.Date;
import java.util.regex.Pattern;

import org.apache.commons.lang3.time.DateUtils;

public class LongEditorSupport extends PropertyEditorSupport{

	public void setAsText(String value) {
		String reg = "\\d{4}-\\d{1,2}-\\d{1,2}\\s\\S*";
		Pattern pattern = Pattern.compile(reg);
		if(pattern.matcher(value).matches()){
			try {
				Date date = DateUtils.parseDate(value, "yyyy-MM-dd hh:mm", "yyyy-MM-dd");
				setValue(date.getTime());
			} catch (ParseException e) {
				System.out.println("转换long型出错......");
				e.printStackTrace();
				setValue(null);
			}
		}
		setValue(value);
	}
	
	public String getAsText() {
		return (String) getValue();
	}
}
